<?php

include_once('ConnectionManager.php');

function insertBa($proID, $path) {
    $sql = "INSERT INTO BANNER (PRO_ID, BANNER_PATH)
                VALUES ($proID, '$path')";
    ConnectionManager::getInstance()->setQuery($sql);
    return ConnectionManager::getInstance()->query();
}

function updateBa(updateBan$bannerID, $proID, $path) {
    $sql = "UPDATE BANNER 
                SET PRO_ID = $proID,
                    BANNER_PATH = '$path'
                WHERE BANNER_ID = $bannerID";
    ConnectionManager::getInstance()->setQuery($sql);
    return ConnectionManager::getInstance()->query();
}

function countTotalNumber() {
    $sql = "SELECT BANNER_ID FROM BANNER";
    ConnectionManager::getInstance()->setQuery($sql);
    ConnectionManager::getInstance()->query();
    return ConnectionManager::getInstance()->getNumRows();
}

function findBannerBy($start_position, $row_per_page) {
    $sql = "SELECT BANNER_ID, PRO_ID, BANNER_PATH, (SELECT PRO_NAME FROM PRODUCT P WHERE P.PRO_ID = B.PRO_ID) as PRONAME
                FROM BANNER B LIMIT $start_position, $row_per_page";
    ConnectionManager::getInstance()->setQuery($sql);
    return ConnectionManager::getInstance()->query();
}

function findBannerPathBy($banID) {
    $sql = "SELECT BANNER_PATH FROM BANNER WHERE BANNER_ID = $banID";
    ConnectionManager::getInstance()->setQuery($sql);
    ConnectionManager::getInstance()->query();
    return ConnectionManager::getInstance()->fetchArray();
}

function deleteBy($id) {
    $sql = "DELETE FROM BANNER WHERE BANNER_ID = $id";
    ConnectionManager::getInstance()->setQuery($sql);
    return ConnectionManager::getInstance()->query();
}

function loadAllBanner() {
    $sql = "SELECT * FROM BANNER";
    ConnectionManager::getInstance()->setQuery($sql);
    return ConnectionManager::getInstance()->query();
}

?>